<!--
2020-##-## 周# by xushenpeng
* IdmBaseSysinfoList.vue
-->
<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="系统代码">
              <a-input placeholder="请输入系统代码" v-model="queryParam.syscode"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="系统名称">
              <a-input placeholder="请输入系统名称" v-model="queryParam.sysname"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="系统类型">
                <!--<a-input placeholder="请输入系统类型" v-model="queryParam.systype"></a-input>-->
                <j-dict-select-tag v-model="queryParam.systype"
                                   dictCode="appl-type" placeholder="请选择系统类型"/>
              </a-form-item>
            </a-col>
            <a-col :xl="10" :lg="11" :md="12" :sm="24">
              <a-form-item label="创建时间">
                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" class="query-group-cust" v-model="queryParam.createdate_begin"></j-date>
                <span class="query-group-split-cust"></span>
                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" class="query-group-cust" v-model="queryParam.createdate_end"></j-date>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="ID"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{fixed:true,selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        :scroll="{x: true}"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="图片不存在" style="max-width:80px;font-size: 12px;font-style: italic;"/>
          <!--<img v-else :src="getImgView(text)" alt="图片不存在"/>-->
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.ID)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <idmBaseSysinfo-modal ref="modalForm" @ok="modalFormOk" :tableName="tableName"></idmBaseSysinfo-modal>
  </a-card>
</template>

<script>
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import IdmBaseSysinfoModal from './modules/IdmBaseSysinfoModal'
  import JDate from '@/components/jeecg/JDate.vue'
  import { postAction } from '@/api/manage'

  export default {
    name: "IdmBaseSysinfoList",
    mixins:[JeecgListMixin],
    components: {
      JDate,
      IdmBaseSysinfoModal
    },
    data () {
      return {
        tableName: 'IDM_BASE_SYSINFO',
        description: 'IDM_BASE_SYSINFO管理页面',
        // 排序参数
        // override mixin
        isorter:{
          column: 'modifydate',
          order: 'desc',
        },
        columns: [
          {
            title: '#', align:"center", dataIndex: '',
            key:'rowIndex',
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          { title:'系统代码', align:"center", dataIndex: 'SYSCODE', width: '10rem' },
          { title:'系统名称', align:"center", dataIndex: 'SYSNAME', width: '10rem' },
          { title:'系统类型', align:"center", dataIndex: 'SYSTYPE_dictText', width: '10rem' },
          { title:'网络类型', align:"center", dataIndex: 'NETTYPE_dictText', width: '10rem' },
          { title:'创建人', align:"center", dataIndex: 'CREATEUSER', width: '10rem' },
          { title:'创建时间', align:"center", dataIndex: 'CREATEDATE', width: '10rem' },
          { title:'修改人', align:"center", dataIndex: 'MODIFYUSER', width: '10rem' },
          { title:'修改时间', align:"center", dataIndex: 'MODIFYDATE', width: '10rem' },
          { title:'登录方式', align:"center", dataIndex: 'API_DICTTEXT', width: '30rem' },
          { title:'访问类型', align:"center", dataIndex: 'APITYPE_dictText', width: '5rem' },
          { title:'图标', align:"center", dataIndex: 'ICON', width: '10rem', scopedSlots: {customRender: 'imgSlot'} },
          { title:'备注', align:"left", dataIndex: 'MARK', width: '20rem' },
          {
            title: '操作', align:"center", dataIndex: 'action', fixed:"right", /*width: '10rem',*/
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/common/select",
          // list: "/basesysinfo/idmBaseSysinfo/list",
          delete: "/crud/delete",
          exportXlsUrl: "/basesysinfo/idmBaseSysinfo/exportXls",
          importExcelUrl: "basesysinfo/idmBaseSysinfo/importExcel",
        },
        dictOptions:{}
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      // override mixin
      loadData(arg) {
        const that = this;
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        const params = this.getQueryParams();//查询条件
        console.log('* loadData: params: ', params);
        const andCriteria = [];
        if (params.syscode) andCriteria.push({column: "syscode", operator: "eq", value: params.syscode});
        if (params.sysname) andCriteria.push({column: "sysname", operator: "eq", value: params.sysname});
        if (params.systype) andCriteria.push({column: "systype", operator: "eq", value: params.systype});
        if (params.createdate_begin) andCriteria.push(
            {column: "createdate", operator: "btw", value: params.createdate_begin, secondValue: params.createdate_end});
        const reqBody = {
          table: this.tableName,
          columnMap: {
            ID: null,
            SYSCODE: null,
            SYSNAME: null,
            // SYSTYPE: {dictInfo: "appl-type"},
            SYSTYPE: null,
            // NETTYPE: {dictInfo: "appl-network-type"},
            NETTYPE: null,
            CREATEDATE: {timeFormat: "datetime"},
            CREATEUSER: null,
            MODIFYDATE: {timeFormat: "datetime"},
            MODIFYUSER: null,
            MARK: null,
            ICON: null,
            API: null,
            APITYPE: {dictCode: "appl-apitype"}
          },
          where: [{or: andCriteria}],
          orderBy: {CREATEDATE: -1, MODIFYDATE: -1},
          pageInfo: {pageSize: this.ipagination.pageSize, pageNo: this.ipagination.current}
        };
        console.log("reqBody: ", reqBody);
        this.loading = true;
        postAction(this.url.list, reqBody)
          .catch(err => console.log('axios err: ', err))
          .then(res => {
            this.dataSource = res.data.result;
            this.ipagination.total = res.data.pageInfo.count;
          })
          .finally(() => this.loading = false);
      },
      // override mixin
      batchDel: function () {
        if(!this.url.delete){
          this.$message.error("请设置url.delete属性!")
          return
        }
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录！');
          return;
        }
        console.log("this.selectedRowKeys: ", this.selectedRowKeys);
        const that = this;
        this.$confirm({
          title: "确认删除",
          content: "是否删除选中数据?",
          onOk: function () {
            that.loading = true;
            // console.log('that.$refs.modalForm.tableName: ', that.$refs.modalForm.tableName)
            const reqBody = {
              table: that.tableName,
              where: that.selectedRowKeys.map(id => ({or: [{column: 'id', operator: 'eq', value: id}]}))
            };
            console.log('reqBody: ', reqBody);
            postAction(that.url.delete, reqBody)
              .catch(err => console.log('axios err: ', err))
              .then(resp => {
                console.log(". resp: ", resp)
                if (resp.code !== 2000) {
                  that.$message.warning(resp.msg);
                  return;
                }
                that.$message.success("批量删除成功!");
                that.loadData();
                that.onClearSelected();
              })
              .finally(() => that.loading = false);
          }
        });
      },
      // override mixin
      handleDelete: function (id) {
        if(!this.url.delete){
          this.$message.error("请设置url.delete属性!")
          return
        }
        // MOD 改用内部通用 CRUD 接口 2020-06-29 周一 09:25:14 by xushenpeng #dlfjkg
        const reqBody = {
          table: this.tableName,
          where: [{or: [{column: "id", operator: "eq", value: id}]}]
        }
        console.log('reqBody: ', reqBody)
        const that = this;
        postAction(this.url.delete, reqBody)
          .catch(err => console.log('axios err: ', err))
          .then(resp => {
            console.log('. resp: ', resp);
            if (resp.code !== 2000) {
              that.$message.warning(resp.msg);
              return;
            }
            that.$message.success("删除成功!");
            that.loadData();
          });
      },
      initDictConfig(){
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>